package com.bjc.base.web;

import com.bjc.base.bean.ResultVO;
import com.bjc.base.core.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.bjc.base.service.IUserContactService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import com.bjc.base.bean.request.UserContactReqVO;
import com.bjc.base.bean.response.UserContactVO;

/**
 * <p>
 * 用户联系方式 前端控制器
 * </p>
 *
 * @author 许自辉
 * @since 2018-06-10
 */
@RestController
@RequestMapping("api/book")
@Api(value = "userContact-api", tags = { "用户联系方式相关接口" })
public class UserContactController {

    @Autowired
    private IUserContactService userContactService;

	@ApiOperation("分页查询用户联系方式")
	@GetMapping("userContact/findPage")
	public ResultVO getUserContactPage(@RequestParam("pageNum") int pageNum, @RequestParam("pageSize") int pageSize,
			UserContactReqVO userContactReqVO) {
		PageHelper.startPage(pageNum, pageSize);
		List<UserContactVO> userContactVOs = userContactService.getList(userContactReqVO);
		return ResultGenerator.getSuccess(new PageInfo<UserContactVO>(userContactVOs));
	}
	
	@ApiOperation("分页查询用户联系方式")
	@GetMapping("userContact/find")
	public ResultVO getUserContacte(UserContactReqVO userContactReqVO) {
		UserContactVO userContactVO = userContactService.get(userContactReqVO);
		return ResultGenerator.getSuccess(userContactVO);
	}

	@ApiOperation("添加用户联系方式")
	@PostMapping("userContact/create")
	public ResultVO createUserContact(@RequestBody UserContactReqVO userContactReqVOs) {
		int count = userContactService.insert(userContactReqVOs);
		return ResultGenerator.getInsertSuccess(count);
	}

	@ApiOperation("更新用户联系方式")
	@PutMapping("userContact/update")
	public ResultVO updateUserContact(@RequestBody UserContactReqVO userContactReqVOs) {
		int count = userContactService.update(userContactReqVOs);
		return ResultGenerator.getUpdateSuccess(count);
	}

	@ApiOperation("批量删除用户联系方式")
	@DeleteMapping("userContact/deleteList")
	public ResultVO deleteUserContact(@ApiParam(value = "userContact id集合") @RequestBody int[] ids) {
		int count = userContactService.deleteList(ids);
		return ResultGenerator.getDeleteSuccess(count);
	}

}
